﻿using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.ReadApi.Command;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander
{
    public class MenuCommandHander : IRequestHandler<MenuCommand, ApiResult<List<Menu>>>
    {
        private readonly IRepistory<Menu> _menuRepository;
        public MenuCommandHander(IRepistory<Menu> menuRepository)
        {
            _menuRepository = menuRepository;
        }
        /// <summary>
        /// 菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<Menu>>> Handle(MenuCommand request, CancellationToken cancellationToken)
        {
           ApiResult<List<Menu>> apiResult=new ApiResult<List<Menu>>();
            apiResult.code = Renum.显示成功;
            apiResult.Message = Renum.显示成功.ToString();
            var list= _menuRepository.GetAll();
            apiResult.Data = list.ToList();
            return Task.FromResult(apiResult);
        }
        
    }
}
